#!/bin/sh
#
# Taken from: http://fasmz.org/~pterjan/qemu-ifup
#
# Sample /etc/qemu-ifup to have bridged networking between qemu instances and your real net
# You need "youruser ALL=(root) NOPASSWD: /etc/qemu-ifup" in /etc/sudoers
# You also need enough rights on /dev/tun
if [ $UID -ne 0 ]
then
	sudo $0 $1
	exit
fi
/sbin/ifconfig $1 promisc 0.0.0.0
if ! /sbin/ifconfig br0
then
	/usr/sbin/brctl addbr br0
	/usr/sbin/brctl addif br0 eth0
	/sbin/ifconfig br0 up
	addr=`/sbin/ip addr | grep eth0 | grep inet | sed -e 's/eth0/dev br0/' -e s/inet//`
	/sbin/ip addr add $addr
fi
brctl addif br0 $1 
brctl stp br0 off
ip route | grep eth0 | while read route
do
newroute=`echo $route | sed s/eth0/br0/ `
ip route del $route
ip route add $newroute
done

